package com.emcom.gotour.mvc.controller;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.MessageSource;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.emcom.gotour.enums.TourType;
import com.emcom.gotour.mvc.message.HomeViewMessage;
import com.emcom.gotour.mvc.view.HomeView;
import com.emcom.gotour.mvc.view.MenuView;
import com.emcom.gotour.po.TourContent;
import com.emcom.gotour.service.TourContentService;
import com.emcom.gotour.vo.ChatVO;

@Controller
public class HomeController {

	@Autowired
	private TourContentService tourContentService;

	@Autowired
	private MessageSource messageSource;

	@Autowired
	private ChatVO chat;

	@RequestMapping(value={"/index.html"})
	public void index(HttpServletRequest request) {
		List<TourContent> popularList = tourContentService.queryPopularContent();
		List<TourContent> zhouBianList = tourContentService.queryImageContent(TourType.ZHOU_BIAN);
		List<TourContent> guoNeiList = tourContentService.queryImageContent(TourType.GUO_NEI);
		List<TourContent> chuJingList = tourContentService.queryImageContent(TourType.CHU_JING);
		List<TourContent> jiuDianList = tourContentService.queryImageContent(TourType.JIU_DIAN);
		List<TourContent> jingDianList = tourContentService.queryImageContent(TourType.JING_DIAN);
		List<TourContent> trainingList = tourContentService.queryImageContent(TourType.TRAINING);
		List<TourContent> anLiList = tourContentService.queryImageContent(TourType.AN_LI);
		TourContent ad = tourContentService.queryAd();
		HomeView view = new HomeView();
		view.setTitle(HomeViewMessage.Title.value(request, messageSource));
		view.setPopularList(popularList);
		view.setZhouBianList(zhouBianList);
		view.setGuoNeiList(guoNeiList);
		view.setChuJingList(chuJingList);
		view.setJiuDianList(jiuDianList);
		view.setJingDianList(jingDianList);
		view.setTrainingList(trainingList);
		view.setAnLiList(anLiList);
		view.setAd(ad);
		view.setMenuView(new MenuView(request, messageSource));
		request.setAttribute("view", view);
		request.setAttribute("chat", chat);
	}

}
